<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <!-- Bootstrap Core CSS -->
<#--<#include "/WEB-INF/views/template/bootMainJs.ftl" parse=true encoding="utf-8">-->
<#include "/WEB-INF/views/template/validator.ftl"  parse=true encoding="utf-8">
    <link rel="stylesheet" href="${basePath}/bootstrap/css/jquery.treegrid.css">
    <link rel="stylesheet" href="${basePath}/bootstrap/plugin/zTree/demo.css">
    <link rel="stylesheet" href="${basePath}/bootstrap/plugin/zTree/metroStyle.css">
    <style>
        .form-group {
            margin-bottom: 0;
        }

        .verify-tip {
            display: none;
            margin-top: 5px;
            margin-bottom: 10px;
            color: #a94442;
            font-size: 85%;
        }

        input[type=radio], input[type=checkbox] {
            vertical-align: top;
        }

        .form-control-checkbox {
            display: inline-block;
            width: 80%;
            vertical-align: top;
        }

        ul.ztree {
            width: auto;
            margin: 0 0 0 100px;
        }
    </style>
</head>
<body>
<div style="padding: 0 15px;">
    <div class="row">
        <div class="col-lg-12">
            <br>
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-12">
                            <form id="myForm">
                                <div class="row">
                                    <div class="col-xs-4 form-group">
                                        <div class="input-group">
                                            <span> 登录名: </span>
                                            <span>${adminUser.loginName!}</span>
                                        </div>
                                        <span class="verify-tip">该登录名已存在!</span>
                                    </div>
                                    <div class="col-xs-4 form-group">
                                        <div class="input-group">
                                            <span>真实姓名: </span>
                                            <span>${adminUser.realName!}</span>
                                        </div>
                                    </div>
                                    <div class="col-xs-4">
                                        <div class="input-group">
                                            <span> 性 别: </span>
                                            <#if adminUser.sex=="1">
                                                <span>男</span>
                                            </#if>
                                            <#if adminUser.sex=="0">
                                                <span>女</span>
                                            </#if>
                                        </div>
                                    </div>
                                </div>
                                <br>
                                <div class="row">
                                    <div class="col-xs-4 form-group">
                                        <div class="input-group">
                                            <span> 电 话: </span>
                                            <span>${adminUser.phone!}</span>
                                        </div>
                                    </div>
                                    <div class="col-xs-4 form-group">
                                        <div class="input-group">
                                            <span> 邮 箱: </span>
                                            <span>${adminUser.email!}</span>
                                        </div>
                                    </div>
                                    <div class="col-xs-4 form-group">
                                        <div class="input-group">
                                            <span>所属部门: </span>
                                            <span>${adminUser.deptName!}</span>
                                        </div>
                                    </div>
                                </div>
                                <br/>
                                <div class="row">
                                    <div class="form-group input-group">
                                        <label>&nbsp;&nbsp;&nbsp;&nbsp;后台用户状态：&nbsp;&nbsp;&nbsp;</label>
                                    <#if adminUser.state==0>
                                        <span>正常使用</span>
                                    </#if>
                                    <#if adminUser.state==2>
                                        <span>锁定用户</span>
                                    </#if>
                                    </div>
                                </div>
                                <br/>
                                <div class="row">
                                    <div class="col-xs-4 form-group">
                                        <div class="input-group">
                                            <span>推荐人: </span>
                                            <#if (adminUser.userId)?? >
                                                <span>${adminUser.userPermission}</span>
                                            <#else >
                                                <span></span>
                                            </#if>
                                        </div>
                                    </div>
                                </div>
                                <hr>
                                <div class="row" align="center">
                                    <div class="col-xs-12">
                                        <button type="button" class="btn btn-primary" onclick="closePage();">关闭</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
<#include "/WEB-INF/views/template/bootMainJs.ftl" parse=true encoding="utf-8">
<script type="text/javascript" src="${basePath}/bootstrap/js/common.js"></script>
<script type="text/javascript"
        src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>');
</script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/zTree/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/zTree/jquery.ztree.excheck.js"></script>
<script type="application/javascript">
    var action = "${action!}";
    var _parent = parent;
    // 初始化
    $(function () {
        if (action == "update") {
            $('#loginName').attr("readonly", "readonly");
        }

        $('#sex').val('${adminUser.sex!}');
        if ($('#sex').val() == null) {
            $('#sex').val("0");
        }
        if ('${adminUser.state!}' == '2') {
            $("input[name=state]:eq(1)").attr("checked", 'checked');
        } else {
            $("input[name=state]:eq(0)").attr("checked", 'checked');
        }
    });

    $(function () {
        $.ajax({
            type: 'GET',
            dataType: "json",
            url: '${basePath}/admin/manager/role/json?userId=${userId?c}',
            success: function (data) {
                var template = '';
                $('#main').html('');
                for (var i = 0; i < data.length; i++) {
                    //template += '<div class="col-xs-3">';
                    if (data[i].checked == 1) {
                        template += '<span data-id="' + data[i].id + '">' + data[i].rlname + '</span>&nbsp;&nbsp;&nbsp;';
                    }
                }
                console.log(template);
                //$('#main').html(template);

//                $('input').iCheck({
//                    checkboxClass: 'icheckbox_flat-blue'
//                });
            }
        });
    });

    //关闭窗口并刷新页面
    function closePage() {
        parent.layer.closeAll();
    }

    if (action == "create") {
        $("#loginName").blur(function () {
            checkName();
        });
    }

    function checkName() {
        var obj = $('#loginName').val();
        var tip = $(".verify-tip");
        if (obj.length > 3) {
            $.ajax({
                type: "GET",
                url: "${basePath}/admin/manager/checkLoginName",
                dataType: 'json',
                data: {
                    loginName: obj
                },
                success: function (data) {
                    if (data == false) {
                        tip.show();
                    }
                    else {
                        tip.hide();
                    }
                },
                error: function () {
                    console.log("请求失败")
                }
            })
        }
    }

    function formSubmit() {
        var bsVal = $("#myForm").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {
            if ($(".verify-tip:visible").length > 0) {
                return false
            }
            else {
                $.ajax({
                    type: 'POST', // You can change this to GET if you want to submit via GET
                    method: $(this).attr('method'),
                    url: '${basePath}/admin/manager/' + action,
                    dataType: 'json',
                    data: {
                        id: $('#id').val(),
                        loginName: $('#loginName').val(),
                        realName: $('#realName').val(),
                        sex: $('#sex').val(),
                        phone: $('#phone').val(),
                        email: $('#email').val(),
                        state: $("input[type='radio']:checked").val()
                    },
                    success: function (data) {
                        if (data.code == '0' || data.code == '0000') {
                            layer.alert('操作成功!', {
                                icon: 6
                            });
                            setTimeout(3000);
                            _parent.search(parseInt(_parent.$('.active').attr('jp-data')));
                            closePage();
                        } else {
                            layer.alert(data.desc, {
                                icon: 5
                            });
                        }
                    },
                    error: function () {
                        layer.alert('系统错误', {
                            icon: 5
                        });
                    }
                })
            }
        }
    }

    $('#myForm').bootstrapValidator({
        fields: {
            loginName: {
                validators: {
                    notEmpty: {
                        message: '请输入登录名'
                    },
                    regexp: {
                        regexp: regName,
                        message: '登录名只能由4到16位的汉字、字母、数字或下划线组成'
                    }
                }
            },
            realName: {
                validators: {
                    notEmpty: {
                        message: '请输入真实姓名'
                    },
                    regexp: {
                        regexp: regRreaName,
                        message: '请输入汉字'
                    }
                }
            },
            phone: {
                validators: {
                    notEmpty: {
                        message: '请输入电话号码'
                    },
                    regexp: {
                        regexp: regTel,
                        message: '电话号码格式不正确'
                    }
                }
            },
            email: {
                validators: {
                    regexp: {
                        regexp: regEmail,
                        message: '邮箱格式不正确'
                    }
                }
            }
        }
    })
</script>
</body>
</html>
